package fons.model.query.fun;

public enum Comparator {
	LESS {
		@Override
		protected boolean compare(double a, double b) {
			return a < b;
		}
	},
	MORE {
		@Override
		protected boolean compare(double a, double b) {
			return a > b;
		}
	},
	EQUAL {
		protected boolean compare(double a, double b) {
			return a == b;
		}
	},
	NOT_EQUAL {
		@Override
		protected boolean compare(double a, double b) {
			return a != b;
		}
	},
	LESS_OR_EQUAL {
		@Override
		protected boolean compare(double a, double b) {
			return a <= b;
		}
	},
	MORE_OR_EQUAL {
		@Override
		protected boolean compare(double a, double b) {
			return a >= b;
		}
	};
	
	public boolean compare (Number a, Number b) {
		if (a.getMeasurement() != null 
			&& b.getMeasurement() != null
			&& !a.getMeasurement().equals(b.getMeasurement())) {
			throw new IllegalArgumentException(a + " and " + b + " cannot be compared!");
		}
		return compare(a.getValue(), b.getValue());
	}
	
	protected abstract boolean compare (double a, double b);
}
